import {defineStore} from 'pinia'
interface UserToken {
    username:string,
    token:string
}

export const useUserStore = defineStore('user',{
    state:()=>{
        return {
            get getToken(){
                return JSON.parse(localStorage.getItem('userToken') as string) 
            },
            set setToken(val:UserToken|null){
                localStorage.setItem('userToken',JSON.stringify(val))
            }   
        }
    },
    actions:{
          LOGIN_IN(val:UserToken){
            this.setToken=val;
          },
          LOGIN_OUT(){
            this.setToken = null;
          }
    }
})